//
//  SINAlertPasswordViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/12.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAlertPasswordViewController.h"

@interface SINAlertPasswordViewController ()
//用户名
@property (weak, nonatomic) IBOutlet UITextField *userNameField;
//验证码输入框
@property (weak, nonatomic) IBOutlet UITextField *codeField;
//获取验证码按钮
@property (weak, nonatomic) IBOutlet UIButton *getCodeButton;
//用户密码
@property (weak, nonatomic) IBOutlet UITextField *passwordField;
//用户密码
@property (weak, nonatomic) IBOutlet UITextField *inputPasswordField;
//确认按钮
@property (weak, nonatomic) IBOutlet UIButton *registerButton;
@end

@implementation SINAlertPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (UI_IS_IPHONE6PLUS) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bar_plus_bg"]  forBarMetrics:UIBarMetricsDefault];
    } else {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bar_bg"]  forBarMetrics:UIBarMetricsDefault];
    }
    
    [self initHeaderView];
    // Do any additional setup after loading the view from its nib.
}
-(void) initHeaderView{
    self.navigationController.navigationBarHidden=YES;
    self.navigationItem.title =@"修改密码";
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.getCodeButton setBackgroundColor:baseButtonBackGroundColor];
    
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];

    NSMutableDictionary *userNameDic = [NSMutableDictionary dictionary];
    userNameDic[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#DDDDDD"];
    NSAttributedString *userNameAttri = [[NSAttributedString alloc] initWithString:@"请输入你的手机号" attributes:userNameDic];
    [self.userNameField setAttributedPlaceholder:userNameAttri];
    
    
    NSMutableDictionary *codeDic = [NSMutableDictionary dictionary];
    codeDic[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#DDDDDD"];
    NSAttributedString *codeAttri = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes:codeDic];
    [self.codeField setAttributedPlaceholder:codeAttri];
    
    
    NSMutableDictionary *passwordDic = [NSMutableDictionary dictionary];
    passwordDic[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#DDDDDD"];
    NSAttributedString *passowrdAttri = [[NSAttributedString alloc] initWithString:@"请设置你的密码" attributes:passwordDic];
    [self.passwordField setAttributedPlaceholder:passowrdAttri];
    
    NSMutableDictionary *inputPasswordDic = [NSMutableDictionary dictionary];
    inputPasswordDic[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#DDDDDD"];
    NSAttributedString *inputPassowrdAttri = [[NSAttributedString alloc] initWithString:@"请输入你的密码" attributes:inputPasswordDic];
    [self.inputPasswordField setAttributedPlaceholder:inputPassowrdAttri];
    
    //设置lable的圆角显示
    self.registerButton.layer.cornerRadius =5;
    //设置lable的边框 宽度为1
    self.registerButton.layer.borderWidth=0;
    //设置lable的边框颜色
    self.registerButton.layer.borderColor=[UIColor redColor].CGColor;
    //设置 显示大小范围为 border内容范围中
    self.registerButton.clipsToBounds = YES;
    [self.registerButton setBackgroundColor: [UIColor colorWithRed:0/255 green:198.0/255 blue:174.0/255 alpha:0.8f]];
    
    self.passwordField.secureTextEntry = YES;
    self.inputPasswordField.secureTextEntry = YES;
}
-(void) backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//返回点击
- (IBAction)backClickFunction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
//确认点击
- (IBAction)regisertClickFunction:(UIButton *)sender {
    
    NSString *userName = self.userNameField.text;
    NSString *code = self.codeField.text;
    NSString *password = self.passwordField.text;
    NSString *inputPassword = self.inputPasswordField.text;
    
    if (userName==nil||[userName isEqualToString:@""]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请输入手机号" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    if (code==nil||[code isEqualToString:@""]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请输入验证码" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    //检测code
    
    
    if (password==nil||[password isEqualToString:@""]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请设置你的密码" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    if (inputPassword==nil||[inputPassword isEqualToString:@""]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请输入密码" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setObject:userName forKey:@"phone"];
    NSString *passwordSign = [SINAMd5Utils md5:password];
    [dict setObject:passwordSign forKey:@"passwords"];
    
    
    //获取系统时间戳
    NSDate* date1 = [NSDate date];
    NSTimeInterval time1 =[date1 timeIntervalSince1970];
    NSString *timeString = [NSString stringWithFormat:@"%.0f",time1];
    DLog(@"系统时间戳:%@",timeString);
    //当前时间
    [dict setObject:timeString forKey:@"signtimes"];
    //唯一标识符
    NSString *uuid = [NSUUID UUID].UUIDString;
    [dict setObject:uuid forKey:@"signuid"];
    //签名
    NSString *signflag = [SINAMd5Utils md5:[NSString stringWithFormat:@"%@%@",uuid,timeString]];
    [dict setObject:signflag forKey:@"signflag"];
    
    [CXAFNHttpRequestUtils httpPostRequest:[NSString stringWithFormat:@"%@%@",baseUrl,userAlertInformationUrl] withParamters:dict success:^(id responseData) {
        NSString *code = responseData[@"code"];
        if ([code isEqualToString:@"1000"]) {
//            NSDictionary *result = responseData[@"content"];
            NSString *message =@"修改密码成功";
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"去登录"cancleBtn:nil];
            alertView.resultIndex = ^(NSInteger index) {
                [self.navigationController popViewControllerAnimated:YES];
            };
            [alertView showXLAlertView];
        }else{
            NSString *message =responseData[@"message"];
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"cancleBtn:nil];
            [alertView showXLAlertView];
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"加载 失败  %@ ",error.debugDescription);
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"修改密码失败" message:@"网络异常" sureBtn:@"确定"cancleBtn:nil];
        [alertView showXLAlertView];
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
